<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>新闻管理系统</title>

    <!-- 引入Vue和Axios -->
    <script src="https://unpkg.com/vue@2.6.14/dist/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

    <!-- 引入Element UI -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>

    <!-- 引入Font Awesome -->
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">

    <style>
        /* 全局样式 */
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f5f7fa;
            color: #333;
        }

        /* 布局样式 */
        .app-container {
            display: flex;
            height: 100vh;
            overflow: hidden;
        }

        /* 侧边栏样式 */
        .sidebar {
            width: 220px;
            background-color: #304156;
            color: #bfcbd9;
            overflow-y: auto;
        }

        .sidebar-header {
            height: 60px;
            line-height: 60px;
            text-align: center;
            background-color: #263445;
            color: #fff;
            font-size: 18px;
            font-weight: bold;
        }

        /* 使用Element UI的菜单组件样式 */
        .el-menu {
            border-right: none;
            background-color: #304156;
            color: #bfcbd9;
        }

        .el-menu-item, .el-submenu__title {
            color: #bfcbd9;
        }

        .el-menu-item:hover, .el-submenu__title:hover {
            background-color: #263445;
        }

        .el-menu-item.is-active {
            background-color: #1890ff;
            color: #fff;
        }

        /* 主内容区域 */
        .main-content {
            flex: 1;
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }

        /* 顶部导航栏 */
        .header {
            height: 60px;
            background-color: #fff;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 20px;
        }

        .header-title {
            font-size: 20px;
            font-weight: bold;
            color: #333;
        }

        .user-info {
            display: flex;
            align-items: center;
            cursor: pointer;
        }

        .user-avatar {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            background-color: #f0f0f0;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 10px;
            font-weight: bold;
            background-image: url("/photo/hhxy3.png"); /* 上级目录的photos文件夹 */
            background-size: contain; /* 修改：使用contain确保图片完全可见 */
            background-position: center;
            background-attachment: scroll; /* 修改：移除fixed属性，或设置为scroll */
            background-repeat: no-repeat; /* 添加：防止图片重复 */
        }


        .user-name {
            font-size: 14px;
            color: #666;
        }

        /* 内容区域 */
        .content-wrapper {
            flex: 1;
            padding: 20px;
            overflow-y: auto;
            background-color: #f5f7fa;
        }

        .content-container {
            background-color: #fff;
            border-radius: 4px;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
            padding: 20px;
            min-height: calc(100% - 40px);
        }

        /* 页面标题 */
        .page-title {
            font-size: 24px;
            font-weight: bold;
            margin-bottom: 20px;
            color: #333;
        }

        /* 响应式布局 */
        @media (max-width: 768px) {
            .app-container {
                flex-direction: column;
            }

            .sidebar {
                width: 100%;
                height: auto;
            }

            .sidebar-header {
                display: none;
            }

            .el-menu {
                display: flex;
                flex-wrap: wrap;
            }

            .el-menu-item, .el-submenu {
                flex: 1 1 auto;
            }
        }
    </style>
</head>
<body>
<div id="app">
    <div class="app-container">
        <!-- 侧边栏 -->
        <div class="sidebar">
            <div class="sidebar-header">
                <i class="fa fa-newspaper-o"></i> 黄淮新闻管理系统
            </div>

            <el-menu
                    default-active="1-1"
                    class="el-menu-vertical-demo"
                    @open="handleOpen"
                    @close="handleClose"
            >
                <el-submenu index="1">
                    <template #title>
                        <i class="fa fa-database"></i>
                        <span>基础数据维护</span>
                    </template>
                    <el-menu-item index="1-1" @click="navigateTo('pages/news/list.html')">
                        <i class="fa fa-list"></i>
                        <span>新闻信息列表</span>
                    </el-menu-item>
                    <el-menu-item index="1-2" @click="navigateTo('pages/news/edit.html')">
                        <i class="fa fa-plus"></i>
                        <span>发布新闻</span>
                    </el-menu-item>
                    <el-menu-item index="1-3" @click="navigateTo('pages/users/list.html')">
                        <i class="fa fa-plus"></i>
                        <span>用户管理</span>
                    </el-menu-item>
                    <el-menu-item index="1-4" @click="navigateTo('Mine.html')">
                        <i class="fa fa-plus"></i>
                        <span>个人管理</span>
                    </el-menu-item>

                </el-submenu>

                <el-submenu index="2">
                    <template #title>
                        <i class="fa fa-cog"></i>
                        <span>系统</span>
                    </template>
                    <el-menu-item index="2-1" @click="navigateTo('pages/user/settings.html')">
                        <i class="fa fa-user"></i>
                        <span>账号设置</span>
                    </el-menu-item>
                </el-submenu>
            </el-menu>
        </div>

        <!-- 主内容区域 -->
        <div class="main-content">
            <!-- 顶部导航栏 -->
            <div class="header">
                <div class="header-title">
                    <i class="fa fa-home"></i> 首页
                </div>

                <div class="user-info" @click="showUserMenu">
                    <div class="user-avatar"></div>
                    <div class="user-name">{{ user.username }}</div>
                    <i class="fa fa-angle-down ml-5"></i>
                </div>
            </div>

            <!-- 内容区域 -->
            <div class="content-wrapper">
                <div class="content-container">
                    <div class="page-title">欢迎使用黄淮新闻管理系统</div>

                    <div class="iframe-container">
                        <iframe
                                id="contentFrame"
                                name="content"
                                width="100%"
                                height="750px"
                                frameborder="0"
                                src="pages/news/list.html"
                        ></iframe>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 用户菜单 -->
    <el-dropdown v-model="showDropdown">
        <template #dropdown>
            <el-dropdown-menu>
                <el-dropdown-item @click="navigateTo('pages/user/settings.html')">
                    <i class="fa fa-user"></i> 个人信息
                </el-dropdown-item>
                <el-dropdown-item @click="navigateTo('pages/user/password.html')">
                    <i class="fa fa-lock"></i> 修改密码
                </el-dropdown-item>
                <el-dropdown-item @click="logout">
                    <i class="fa fa-sign-out"></i> 退出登录
                </el-dropdown-item>
            </el-dropdown-menu>
        </template>
    </el-dropdown>

</div>

<script>
    new Vue({
        el: '#app',
        data() {
            return {
                showDropdown: false,
                userName: '',
                contentUrl: 'pages/news/list.html',
                user:{} // 用户对象
            };
        },
        computed: {
            userInitials() {
                return this.userName.charAt(0).toUpperCase();
            }
        },
        methods: {
            handleOpen(key, keyPath) {
                console.log(key, keyPath);
            },
            handleClose(key, keyPath) {
                console.log(key, keyPath);
            },
            navigateTo(url) {
                this.contentUrl = url;
                this.showDropdown = false;
                document.getElementById('contentFrame').src = url;
            },
            showUserMenu() {
                this.showDropdown = !this.showDropdown;
            },
            logout() {
                this.$confirm('确定要退出登录吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    // 这里实现退出登录逻辑
                    this.$message.success('已退出登录');
                    // 模拟退出登录后跳转到登录页
                    setTimeout(() => {
                        window.location.href = 'login.html';
                    }, 1000);
                }).catch(() => {
                    // 取消操作
                });
            }
        },created() {
            const userData = sessionStorage.getItem("user");
            // 如果存储的数据是 JSON 格式的字符串，需要将其解析为 JavaScript 对象
            if (userData) {
                this.user = JSON.parse(userData);
                console.log(user); // 打印解析后的 user 对象
            } else {
                console.log("没有找到存储的用户数据");
            }

            this.findUserById(user.userId);
        }
    });
</script>
</body>
</html>
